<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      ;(function (history) {
        var pushState = history.pushState
        history.pushState = function (state) {
          if (typeof history.onpushstate == 'function') {
            console.log(22222)
            history.onpushstate({ state: state })
          }
          return pushState.apply(history, arguments)
        }
      })(window.history)
      //设置其方法和popstate相同即可
      window.popstate = history.onpushstate = function (event) {
        alert(
          'location: ' +
            document.location +
            ', state: ' +
            JSON.stringify(event.state)
        )
      }
    </script>
  </body>
</html>
